from czllblog import settings
from System.models import *
from rest_framework import serializers

##继承序列化类
class NavSerializer(serializers.ModelSerializer):
    class Meta:
        model = Nav
        #序列化所有字段
        fields = ('id', 'name',)

#轮播图
class CarouselSerializer(serializers.ModelSerializer):
    img = serializers.SerializerMethodField()
    class Meta:
        model = Carousel
        #序列化所有字段
        fields = ('id', 'name','img',)

    def get_img(self, obj):
        rel_path = obj['img']
        rely_on_path = settings.MEDIA_URL
        return rely_on_path + rel_path

